package com.qf.controller;

import com.qf.pojo.User;
import com.qf.service.UserService;
import com.qf.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Author:zhangyang
 * @Date: 11:51
 * @Version 1.0
 */
@WebServlet("/findUserList")
public class FindUserListServlet  extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        //1)直接调用service查询用户列表数据
        UserService userService = new UserServiceImpl() ;
        List<User> list = userService.getUserList() ;

        //2)请求转发到list.jsp页面下展示数据
        if(list!=null){
            //存储request域中
            request.setAttribute("list",list);
            request.getRequestDispatcher("/list.jsp").forward(request,response);
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
